//
//  ProdDetailFooterView.m
//  JiaoX
//
//  Created by yinqy on 15/1/13.
//  Copyright (c) 2015年 北京娇羞科技有限公司. All rights reserved.
//

#import "ProdDetailFooterView.h"

#define NAME_FONT_SIZE 14
#define CONTENT_FONT_SIZE 13

@interface ProdDetailFooterView()
{
    UILabel *_nameLabel;
    UILabel *_timeLabel;
    UILabel *_contentLabel;
    UIView *_splite1;
    UIView *_splite2;
    
    UIImageView *_genderImg;
}

@end
@implementation ProdDetailFooterView

- (instancetype)initWithComtInfo:(CommentInfo *)info
{
    self = [super init];
    if (self) {
        UIView *splite = [[UIView alloc]init];
        [splite setFrame:CGRectMake(JXPublicInset, 0, JXScreenW-JXPublicInset, 0.5)];
        [splite setBackgroundColor:SEPARATORCOLOR];
//        [self addSubview:splite];
        if (info==nil) {
            [self setFrame:CGRectMake(0, 0, JXScreenW, 0.5)];
        }else{
            //名字
            _nameLabel = [[UILabel alloc]init];
            [_nameLabel setTextColor:JXColor(102, 102, 102)];
            [_nameLabel setFont:[UIFont systemFontOfSize:NAME_FONT_SIZE]];
            CGSize nameSize = [info.commentName sizeWithFont:[UIFont systemFontOfSize:NAME_FONT_SIZE]];
            [_nameLabel setFrame:CGRectMake(30, JXPublicInset, nameSize.width, nameSize.height)];
            [_nameLabel setText:info.commentName];
            [self addSubview:_nameLabel];
            
            NSString *genderStr = [Utils getGenderStrWithGender:[NSString stringWithFormat:@"%@",info.commentGender] level:info.commentLevel isLarge:YES];
            _genderImg = [[UIImageView alloc]initWithImage:IMG(genderStr)];
            [_genderImg setSize:_genderImg.image.size];
            [_genderImg setCenterY:_nameLabel.centerY];
            [_genderImg setX:CGRectGetMaxX(_nameLabel.frame)+5];
            [self addSubview:_genderImg];
            
            //时间
            _timeLabel = [[UILabel alloc]init];
            [_timeLabel setFont:[UIFont systemFontOfSize:NAME_FONT_SIZE]];
            [_timeLabel setTextColor:JXColor(102, 102, 102)];
            CGSize timeSize = [info.commentTime sizeWithFont:[UIFont systemFontOfSize:NAME_FONT_SIZE]];
            [_timeLabel setFrame:CGRectMake(JXScreenW-JXPublicInset-timeSize.width, JXPublicInset, timeSize.width, timeSize.height)];
            [_timeLabel setText:info.commentTime];
            [_timeLabel setHidden:YES];
            [self addSubview:_timeLabel];
            
            //添加分割线
            _splite1 = [[UIView alloc]init];
            [_splite1 setFrame:CGRectMake(CGRectGetMinX(_nameLabel.frame), CGRectGetMaxY(_nameLabel.frame)+JXPublicInset, JXScreenW-JXPublicInset, 0.5)];
            [_splite1 setBackgroundColor:SEPARATORCOLOR];
            [self addSubview:_splite1];
            
            //内容
            _contentLabel = [[UILabel alloc]init];
            [_contentLabel setFont:[UIFont systemFontOfSize:CONTENT_FONT_SIZE]];
            [_contentLabel setTextColor:JXColor(102, 102, 102)];
            CGSize contentSize = [info.commentContent sizeWithFont:[UIFont systemFontOfSize:CONTENT_FONT_SIZE] constrainedToSize:CGSizeMake(JXScreenW-JXPublicInset-50, MAXFLOAT)];
            [_contentLabel setFrame:CGRectMake(CGRectGetMinX(_nameLabel.frame)+20, CGRectGetMaxY(_splite1.frame)+JXPublicInset, contentSize.width, contentSize.height)];
            [_contentLabel setText:info.commentContent];
            [_contentLabel setNumberOfLines:0];
            [self addSubview:_contentLabel];
            
            //添加分割线
            _splite2 = [[UIView alloc]init];
            [_splite2 setFrame:CGRectMake(CGRectGetMinX(_contentLabel.frame), CGRectGetMaxY(_contentLabel.frame)+JXPublicInset, JXScreenW-JXPublicInset, 0.5)];
            [_splite2 setBackgroundColor:SEPARATORCOLOR];
            [self addSubview:_splite2];
            
            [self setFrame:CGRectMake(0, 0, JXScreenW, CGRectGetMaxY(_splite2.frame))];
        }
    }
    return self;
}

@end
